﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Core;

/// <summary>
/// 全局UI静态方法
/// </summary>
public static class AbcUI
{
    /// <summary>
    /// 是否有授权
    /// </summary>
    /// <param name="controller">控制器</param>
    /// <param name="action">方法</param>
    /// <returns></returns>
    public static bool IsAuthorize(string controller, string action)
    {
        return IsAuthorizeAsync(controller, action).GetAwaiter().GetResult();
    }

    /// <summary>
    /// 是否有授权
    /// </summary>
    /// <param name="controller">控制器</param>
    /// <param name="action">方法</param>
    /// <returns></returns>
    public static async Task<bool> IsAuthorizeAsync(string controller, string action)
    {
        var _cacheService = App.GetService<ISysCacheService>();
        return await _cacheService.HasAuthorize(controller: controller, action: action);
    }

    /// <summary>
    /// 是否有授权
    /// </summary>
    /// <param name="controller">控制器</param>
    /// <param name="action">方法</param>
    /// <param name="menuAreaType"></param>
    /// <param name="area"></param>
    /// <returns></returns>
    public static async Task<bool> IsAuthorizeAsync(string controller, string action, MenuAreaType menuAreaType = MenuAreaType.Mvc, string area = "HtAdmin")
    {
        var _cacheService = App.GetService<ISysCacheService>();
        return await _cacheService.HasAuthorize(controller: controller, action: action, menuAreaType: menuAreaType, area: area);
    }
}